home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / WindowColorMap.C < prev    next >
C/C++ Source or Header  |  1992-08-26  |  3KB  |  157 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "WindowColorMap.h"
  6. #include "Class.h"
  7. #include "String.h"
  8.  
  9. //---- WindowColorMap -------------------------------------------------------
  10.  
  11. NewMetaImpl(WindowColorMap,Object, (T(id), TB(rw), T(changed)));
  12.  
  13. int WindowColorMap::cnt= 1000;
  14.  
  15. WindowColorMap::WindowColorMap()
  16. {
  17.     id= WindowColorMap::cnt++;
  18.     changed= 0;
  19.     rw= TRUE;
  20.     grey= FALSE;
  21. }
  22.  
  23. WindowColorMap::WindowColorMap(WindowColorMap *from)
  24. {
  25.     id= WindowColorMap::cnt++;
  26.     changed= 0;
  27.     rw= from->rw;
  28.     grey= from->grey;
  29. }
  30.  
  31. WindowColorMap::~WindowColorMap()
  32. {
  33. }
  34.  
  35. WindowColorMap *WindowColorMap::DevMakeCopy(WindowColorMap*)
  36. {
  37.     return this;
  38. }
  39.  
  40. void WindowColorMap::Unref()
  41. {
  42.     if (refcnt > 0) {
  43.     refcnt--;
  44.     if (refcnt == 0)
  45.         delete this;
  46.     }
  47. }
  48.  
  49. u_long WindowColorMap::AllocateAndSetCell(long id, RGB *rgb, WindowPort *port)
  50. {
  51.     if (rw)
  52.     return DevAllocateAndSetCell(id, rgb, port);
  53.     return RGB2Index(rgb);
  54. }
  55.  
  56. void WindowColorMap::DevInstall(Port*)
  57. {
  58.     changed= 0;
  59. }
  60.  
  61. u_long WindowColorMap::DevRGB2Index(RGB *c, RGB*)
  62. {
  63.     return DevRGB2Index2(c);
  64. }
  65.  
  66. u_long WindowColorMap::DevRGB2Index2(RGB*)
  67. {
  68.     return 0;
  69. }
  70.  
  71. void WindowColorMap::DevIndex2RGB(u_long, RGB*)
  72. {
  73. }
  74.  
  75. u_long WindowColorMap::DevAllocateAndSetCell(long, RGB*, WindowPort*)
  76. {
  77.     return 0;
  78. }
  79.  
  80. //---- WindowColorMap -------------------------------------------------------
  81.  
  82. NewMetaImpl(WindowIndexMapper,WindowColorMap, (T(length)));
  83.  
  84. WindowIndexMapper::WindowIndexMapper() : WindowColorMap()
  85. {
  86.     length= 0;
  87.     realmap= new RGB[256];
  88.     graymap= new u_long[256];
  89.     rgbmap= new u_long[256];
  90. }
  91.  
  92. WindowIndexMapper::WindowIndexMapper(WindowIndexMapper *from)
  93.                              : WindowColorMap(from)
  94. {
  95.     length= from->length;
  96.     realmap= new RGB[256];
  97.     memcpy(realmap, from->realmap, 256 * sizeof(RGB));
  98.     graymap= new u_long[256];
  99.     memcpy(graymap, from->graymap, 256 * sizeof(u_long));
  100.     rgbmap= new u_long[256];
  101.     memcpy(rgbmap, from->rgbmap, 256 * sizeof(u_long));
  102. }
  103.  
  104. WindowIndexMapper::~WindowIndexMapper()
  105. {
  106.     SafeDelete(realmap);
  107.     SafeDelete(graymap);
  108.     SafeDelete(rgbmap);
  109. }
  110.  
  111. u_long WindowIndexMapper::DevRGB2Index(RGB *c, RGB *result)
  112. {
  113.     u_long id, ix;
  114.     
  115.     if (grey || (c->red == c->green && c->green == c->blue)) {
  116.     if (grey)
  117.         id= c->AsGreyLevel();
  118.     else
  119.         id= c->red;
  120.     ix= graymap[id];
  121.     if (ix == 0) {
  122.         RGB rc((short)((id / (MAXGREYS-1)) * (MAXGREYS-1)));
  123.         graymap[id]= ix= DevRGB2Index2(&rc);
  124.     }
  125.     /*
  126.     if (type[ix])
  127.         ix= graymap[v]= FindGray(v);
  128.     */
  129.     } else {
  130.     id= Pixel(c->red, c->green, c->blue);
  131.     ix= rgbmap[id];
  132.     if (ix == 0) {
  133.         RGB rc;
  134.         rc.red= (c->red / (MAXREDS-1)) * (MAXREDS-1);
  135.         rc.green= (c->green / (MAXGREENS-1)) * (MAXGREENS-1);
  136.         rc.blue= (c->blue / (MAXBLUES-1)) * (MAXBLUES-1);
  137.         rgbmap[id]= ix= DevRGB2Index2(&rc);
  138.     }
  139.     
  140.     /*
  141.     if (type[ix])
  142.         ix= FindRGB(c);
  143.     */
  144.     }
  145.     // usecnt[ix]++;
  146.     
  147.     if (result)
  148.     *result= realmap[ix];
  149.     return ix;
  150. }
  151.  
  152. void WindowIndexMapper::DevIndex2RGB(u_long ix, RGB *result)
  153. {
  154.     *result= realmap[ix];
  155. }
  156.  
  157.